﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Slwy.Utility.Extensions;

namespace Slwy.Data.Entity.Attributes
{
    public class DbConnectionNameAttribute : Attribute
    {
        public string DbConnectionName { get; set; }

        public string Suffix { get; set; } = string.Empty;

        public DbConnectionNameAttribute(string dbConnectionName, string suffix = "")
        {
            this.DbConnectionName = dbConnectionName;
            this.Suffix = suffix;
        }
    }

    public static partial class ObjectException
    {
        public static string GetDbConnectionName(this MemberInfo value) 
        {
            var desc = value.GetAttribute<DbConnectionNameAttribute>(true);
            return desc != null ? desc.DbConnectionName : string.Empty;
        }
    }
}
